package com.ycc.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycc.biz.common.PageResult;
import com.ycc.biz.common.Result;
import com.ycc.biz.pojo.entity.BizAttachment;
import com.ycc.biz.pojo.entity.BizCategory;
import com.ycc.biz.pojo.query.BizCategoryQuery;
import com.ycc.biz.service.BizAttachmentService;
import com.ycc.biz.service.BizCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName: BizCategoryController
 * @author: ycl
 * @date: 2025/03/28 16:31:08
 */
@Api(tags = "分类管理")
@RestController
@RequestMapping("/category")
@AllArgsConstructor
public class BizCategoryController {
    private final BizCategoryService bizCategoryService;

    @ApiOperation("添加分类")
    @PostMapping("/addCategory")
    public Result<Boolean> addCategory(@ApiParam("分类信息") @RequestBody BizCategory category) {
        bizCategoryService.save(category);
        return Result.success(true);
    }

    @ApiOperation("删除分类")
    @PostMapping("/deleteCategory")
    public Result<Boolean> deleteCategory(@RequestParam String id) {
        return Result.success(bizCategoryService.removeById(id));
    }

    @ApiOperation("更新分类")
    @PostMapping("/updateCategory")
    public Result<Boolean> updateCategory(@ApiParam("分类信息") @RequestBody BizCategory category) {
        return Result.success(bizCategoryService.updateById(category));
    }

    @ApiOperation("根据ID查询分类")
    @PostMapping("/getCategoryById")
    public Result<BizCategory> getCategoryById(@RequestParam String id) {
        return Result.success(bizCategoryService.getById(id));
    }

    @ApiOperation("查询全部分类")
    @PostMapping("/listCategories")
    public Result<List<BizCategory>> listCategories() {
        return Result.success(bizCategoryService.list());
    }

    @ApiOperation("分页查询分类")
    @PostMapping("/pageCategories")
    public Result<PageResult<BizCategory>> pageCategories(@RequestBody BizCategoryQuery query) {
        return Result.success(bizCategoryService.pageCategories(query));
    }
}
